package com.sfdk.admin.structure
{

    import flash.utils.IDataInput;
	import flash.utils.IDataOutput;
	import flash.utils.IExternalizable;
	
	import mx.collections.ListCollectionView;
	import mx.core.mx_internal;
	
	use namespace mx_internal;
	
	[DefaultProperty("source")]

	public class VectorCollection extends ListCollectionView implements IExternalizable
	{
	    //--------------------------------------------------------------------------
	    //
	    //  Constructor
	    //
	    //--------------------------------------------------------------------------
	
	    /**
	     *  Constructor.
	     *
	     *  <p>Creates a new VectorCollection using the specified source vector.
	     *  If no vector is specified an empty array will be used.</p>
	     */
	    public function VectorCollection(source:Object = null)
	    {
	        super();
	
	        this.source = source;
	    }
	
	    //--------------------------------------------------------------------------
	    //
	    //  Properties
	    //
	    //--------------------------------------------------------------------------
	
	    //----------------------------------
	    //  source
	    //----------------------------------
	
	    [Inspectable(category="General", arrayType="Object")]
	    [Bindable("listChanged")] //superclass will fire this
	
	    /**
	     *  The source of data in the VectorCollection.
	     *  The VectorCollection object does not represent any changes that you make
	     *  directly to the source array. Always use
	     *  the ICollectionView or IList methods to modify the collection.
	     */
	    public function get source() : Object
	    {
	        if (list && (list is VectorList))
	        {
	            return VectorList(list).source;
	        }
	        return null;
	    }
	
	    /**
	     *  @private
	     */
	    public function set source(s : Object):void
	    {
	        list = new VectorList(s);
	    }
	
	    //--------------------------------------------------------------------------
	    //
	    //  Methods
	    //
	    //--------------------------------------------------------------------------
	
	    /**
	     *  @private
	     *  Ensures that only the source property is serialized.
	     */
	    public function readExternal(input:IDataInput):void
	    {
	        if (list is IExternalizable)
	            IExternalizable(list).readExternal(input);
	        else
	            source = input.readObject() as Array;
	    }
	
	    /**
	     *  @private
	     *  Ensures that only the source property is serialized.
	     */
	    public function writeExternal(output:IDataOutput):void
	    {
	        if (list is IExternalizable)
	            IExternalizable(list).writeExternal(output);
	        else
	            output.writeObject(source);
	    }
	}
}